package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfAlarmTemplate;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfAlarmTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
/**
 * 告警模板表-Controller
 * @author zfsn
 * @date 2023-4-3
 */
@Api(tags = "告警配置管理-告警模板配置")
@RestController
@RequestMapping("/alarmTemplate")
public class ConfAlarmTemplateController {

	@Autowired
	private ConfAlarmTemplateService confAlarmTemplateService;

	/**
	 * 通过主键查询数据
	 * @param id 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{id}")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "query", required = true, dataTypeClass = Integer.class)
	})
	public R<ConfAlarmTemplate> queryByIds(@PathVariable("id") Integer id) {
		return R.ok(confAlarmTemplateService.getById(id));
	}

	/**
	 * 分页查询
	 * @param confAlarmTemplate 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "模板类型，1：基础告警，2：统计告警", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "isEnable", value = "是否启用，0：启用(默认)、1：禁用", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "name", value = "模板名称", paramType = "body", required = false, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "orderByColumn", value = "排序列", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isAsc", value = "排序的方向值只能是 desc 或者 asc", paramType = "body", required = true, dataType = "String")
	})
	public R<Page<ConfAlarmTemplate>> listPage(@RequestBody @ApiIgnore ConfAlarmTemplate confAlarmTemplate) {
		return R.ok(confAlarmTemplateService.listPage(confAlarmTemplate));
	}

	/**
	 * 新增数据
	 * @param confAlarmTemplate 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增告警模板表数据")
	@PostMapping("/save")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "模板类型，1：基础告警，2：统计告警", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "name", value = "模板名称", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "description", value = "模板说明", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "content", value = "模板内容", paramType = "body", required = true, dataType = "String"),
	})
	public R<String> save(@RequestBody @ApiIgnore ConfAlarmTemplate confAlarmTemplate) {
		return confAlarmTemplateService.saveConfig(confAlarmTemplate);
	}

	/**
	 * 通过主键更新数据
	 * @param confAlarmTemplate 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新告警模板表数据")
	@PutMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "主键", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "type", value = "模板类型，1：基础告警，2：统计告警", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "name", value = "模板名称", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "description", value = "模板说明", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "content", value = "模板内容", paramType = "body", required = true, dataType = "String"),
	})
	public R<String> updateById(@RequestBody @ApiIgnore ConfAlarmTemplate confAlarmTemplate) {
		return confAlarmTemplateService.updateConfigById(confAlarmTemplate);
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除告警模板表数据")
	@DeleteMapping("/delete/{ids}")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "id(支持多选)", paramType = "query", required = true, dataTypeClass = Integer.class)
	})
	public R<Boolean> removeById(@PathVariable("ids") List<Integer> ids){
		return R.ok(confAlarmTemplateService.removeByIds(ids));
	}


	/**
	 * 修改是否启用状态
	 *
	 * @param confAlarmTemplate
	 * @return 结果
	 */
	@SysLog("删除告警模板表数据")
	@ApiOperation(value = "修改是否启用状态", notes = "修改是否启用状态")
	@PostMapping("/updateTemplateEnable")
	public R<String> updateTemplateEnable(@RequestBody ConfAlarmTemplate confAlarmTemplate){
		return confAlarmTemplateService.updateTemplateEnable(confAlarmTemplate);
	}
}